const ly = require("../models/pl")
//获取所有博客信息
exports.getboke = async function () {
    const result = await ly.findAll()
    return result;
}

// 分页查询
const {
    Op,
    where
} = require("sequelize");
// const Class = require("../models/Class")
exports.getfenye = async function (page = 1, limit = 2, keywords = "") {
    const where = {
        [Op.or]: [{
            name: {
                [Op.like]: `%${keywords}%`
            }
        }, ]
    };
    const result = await ly.findAndCountAll({
        offset: (page - 1) * limit,
        limit: +limit,
        where
    })
    return JSON.parse(JSON.stringify(result))
}
//查
exports.getIdfind = async function (page = 1, limit = 10, id) {
    const result = await ly.findAndCountAll({
        offset: (page - 1) * limit,
        limit: +limit,
        where: {
            id
        }
    })
    return JSON.parse(JSON.stringify(result))
}
//添加修改
exports.updateBoke = async function (id, obj) {
    return await ly.update(obj, {
        where: {
            id
        }
    });
}

exports.add = async function (obj) {
    await ly.create(obj)
}

const boke =require("../models/boke")
exports.getfindall = async function (bokeid) {

    const result = await ly.findAndCountAll({
        include:[boke],
        where: {
            bokeid
        }
    })
    return JSON.parse(JSON.stringify(result))
}